package com.iflyun.rabbitmq.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.iflyun.rabbitmq.bean.Result;
import com.iflyun.rabbitmq.common.Common;
import com.iflyun.rabbitmq.utils.MailUtils;
import com.iflyun.rabbitmq.utils.RabbitmqUtils;


@Controller
@RequestMapping("/test")
public class TestController {
	
	@RequestMapping("/mail")
	public String testMail(){
		int ready = 0;
		int unacknowledged = 0;
		int auto_delete = 0;
		int durable = 0;
		Map<String, Integer> map = RabbitmqUtils.CheckCustomer("Weblog");
		ready = map.get("ready");
		unacknowledged = map.get("unacknowledged");
		auto_delete = map.get("auto_delete");
		durable = map.get("durable");
		if (ready > Common.Error || unacknowledged > Common.Error) {
			MailUtils.Send(Common.prefix + "consumption Exception: accumulation value of more than 5000 ",
					"941911337@qq.com,wenquxing@iflyun.com");
		} else if (ready > Common.Warn || unacknowledged > Common.Warn) {
			MailUtils.Send(Common.prefix + "consumption Warning: second accumulation value of more than 2000",
					"941911337@qq.com,wenquxing@iflyun.com");
		}
		if (auto_delete != 1) {
			MailUtils.Send(Common.prefix + "Queue Weblog-auto_delete flag is not false",
					"941911337@qq.com,wenquxing@iflyun.com");

		}
		if (durable != 0) {
			MailUtils.Send(Common.prefix + "Queue Weblog-durable flag is not true",
					"941911337@qq.com,wenquxing@iflyun.com");

		} else {
			MailUtils.Send(Common.prefix + "consumption Normal", "941911337@qq.com,wenquxing@iflyun.com");
		}
		Result result = RabbitmqUtils.CheckQueue("Weblog");
		MailUtils.Send(Common.prefix + result.getMsg(), "941911337@qq.com,wenquxing@iflyun.com");
		return null;
		
	}
	
}
